-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pre commit Hooks (black, flake8, mypy, etc) [CT-105] #4639
Conversation
@iknox-fa have you tried running this yet to see what we need to fix up in our code base? I'm guessing we don't abide by this perfectly right now 😄 |
Also we should add something to the Contributing file so contributors know to expect this to fail during commits if they have issues |
I'm guessing that this doesn't limit itself to the things that were just changes, so this should include a reformatting of the entire codebase, right? In particular we have never event run flake8 on the test directories. I'm wondering if it might not be easier to skip the test/unit and test/integration directories for now, since they're going to change a lot soon. |
Its... a lot. 306 of 332 files were reformatted when I did a test run locally. |
Good call. Updated |
Be default it just corrects files that you are currently trying to commit, but you can run it against everything of course. We will want to run it against everything just to minimize the confusion that might come from a PR touching so many files, but I'd like to do it in a separate PR.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! Can we please enforce these pre-commit hooks in CI and move the black config (line length) to a config file (pyproject.toml
) so that IDEs, editors, and running black .
directly on the cli can all use the same config?
I went ahead and put this in another ticket, as it may cause issues with some of the other tools that build/interact with dbt. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some references in CONTRIBUTING.md to tox and flake8/mypy, can you update this as well?
https://github.com/dbt-labs/dbt-core/blob/pre-commit-CT-105/CONTRIBUTING.md#tox
tox.ini
Outdated
@@ -2,25 +2,6 @@ | |||
skipsdist = True | |||
envlist = py37,py38,py39,flake8,mypy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
envlist = py37,py38,py39,flake8,mypy | |
envlist = py37,py38,py39 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Updated!
.github/workflows/main.yml
Outdated
- name: Run tox | ||
run: tox | ||
- name: Run pre-commit hooks | ||
run: pre-commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be something like:
run: pre-commit | |
run: pre-commit --all-files --show-diff-on-failure |
There are no staged files when this workflow runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh good catch (show-diff-on-failures
doesn't seem to be a thing however). Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! and more on --show-diff-on-failure
here. totally optional but I've found it helpful in CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
failure
singular! whomp whomp adding it now.
Makefile
Outdated
@\ | ||
$(DOCKER_CMD) pre-commit run flake8 | grep -v "[INFO]"; \ | ||
$(DOCKER_CMD) pre-commit run mypy | grep -v "[INFO]"; \ | ||
$(DOCKER_CMD) pre-commit run black | grep -v "[INFO]" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only run on git staged files. Is that what is intended here?
|
Whoops. Missed this comment initially. Fixed now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I'd love if someone else from the team could take this for a spin as well 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working to meet my linting needs on this one!
resolves #3195 Jira CT-105
Description
Adds a selection of pre-commit hooks, most importantly the black formatter.
Moves non-environment dependent tests to pre-commit and out of tox (mypy and flake8)
To enable the pre-commit hooks simply
make dev
.Checklist